package com.bluesky.example.concurrent;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.net.UnknownHostException;

public class WebClient implements Runnable {
	String server;

	public WebClient(String serverHost) {
		this.server = serverHost;
	}

	@Override
	public void run() {
		Socket socket = null;
		try {
			socket = new Socket(server, 80);
			InputStreamReader sr = new InputStreamReader(socket
					.getInputStream());
			BufferedReader reader = new BufferedReader(sr);

			OutputStreamWriter sw = new OutputStreamWriter(socket
					.getOutputStream());
			BufferedWriter writer = new BufferedWriter(sw);

			reader.readLine();
			reader.readLine();
			 

			writer.write("helo");
			writer.newLine();
			writer.flush();

			reader.readLine();
			writer.write("quit");
			writer.newLine();
			writer.flush();

			reader.readLine();

		} catch (Exception e) {

			e.printStackTrace();
		} finally {
			try {
				socket.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

	}

}
